//
//  ChannelAccessTableViewCell.m
//  UI_22_Homework_QQ音乐界面_阿里星球界面
//
//  Created by li cheng on 16/8/13.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ChannelAccessTableViewCell.h"
#import "ChannelAccessCollectionViewCell.h"
@interface ChannelAccessTableViewCell()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end
@implementation ChannelAccessTableViewCell
#pragma mark - 初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        [self.contentView addSubview:_collectionView];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        [_collectionView registerClass:[ChannelAccessCollectionViewCell class] forCellWithReuseIdentifier:@"ChannelAccessCollectionViewCell"];
    }
    return self;
}
#pragma mark - 布局
- (void)addSubview:(UIView *)view{
    [super addSubview:view];
    _collectionView.frame = self.contentView.bounds;
    CGFloat itemSizeHeight = self.collectionView.bounds.size.height;
    CGFloat itemSizeWidth = itemSizeHeight;
    _layout.itemSize = CGSizeMake(itemSizeWidth, itemSizeHeight);
    _layout.minimumLineSpacing = 0;
    CGFloat edge = 5;
    CGFloat minimumInteritemSpacingValue = (self.contentView.bounds.size.width - 3 * itemSizeWidth - 2 * edge) / 2;
    _layout.minimumInteritemSpacing = minimumInteritemSpacingValue;
    _layout.sectionInset = UIEdgeInsetsMake(0, edge, 0, edge);
}
#pragma mark - collectionView 的代理方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ChannelAccessCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChannelAccessCollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor blueColor];
    return cell;
}
#pragma mark - 其他
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

